package com.outsider.note.controller;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.outsider.interceptor.ResponseHeaderInterceptor;
import com.outsider.note.dao.TextNote;
import com.outsider.note.dao.VoiceNote;
import com.outsider.note.service.VoiceNoteService;
import com.outsider.util.Const;
import com.outsider.weixin.dao.User;

@Before(ResponseHeaderInterceptor.class)
public class VoiceNoteController extends Controller{
    private VoiceNoteService voiceNoteService=new VoiceNoteService();
    //flag=0 返回全部 
    //flag=1 返回未生效的list
    public void getNote(){
    	int flag=getParaToInt("flag");
    	String openID=getPara(Const.OPEN_ID);
		int page=getParaToInt("page");
		int row=getParaToInt("row");
    	int userID=User.dao.findIDbyOpenID(openID);
    	Page<VoiceNote> list;
    	if (flag==0)
    		list=VoiceNote.dao.findAllNote(row,page,userID);
    	else
    		list=VoiceNote.dao.findNotExpiredNote(row,page,userID);
    	renderJson("page",list);
    }
    
    public void delete(){
    	int ID=getParaToInt();
    	voiceNoteService.deleteVoiceNote(VoiceNote.dao.findById(ID));
    	renderJson(Const.RESULT, Const.SUCCESS);
    }
    public void update(){
    	getModel(VoiceNote.class).update();
    	renderJson(Const.RESULT, Const.SUCCESS);
    }
}
